package com.ruoyi.web.controller.ziran;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.system.service.ISysUserService;
import com.ruoyi.ziran.domain.ZrPaperUser;
import com.ruoyi.ziran.service.IZrPaperUserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ziran.domain.ZrReport;
import com.ruoyi.ziran.service.IZrReportService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 上报处理Controller
 * 
 * @author ruoyi
 * @date 2024-10-29
 */
@Controller
@RequestMapping("/ziran/zrReport")
public class ZrReportController extends BaseController
{
    private String prefix = "ziran/zrReport";

    @Autowired
    private IZrReportService zrReportService;
    @Autowired
    private IZrPaperUserService iZrPaperUserService;
    @Autowired
    private ISysUserService iSysUserService;

    //@RequiresPermissions("ziran:zrReport:view")
    @GetMapping()
    public String zrReport()
    {
        return prefix + "/zrReport";
    }

    /**
     * 查询上报处理列表
     */
    //@RequiresPermissions("ziran:zrReport:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ZrReport zrReport)
    {
        startPage();
        List<ZrReport> list = zrReportService.selectZrReportList(zrReport);
        return getDataTable(list);
    }

    /**
     * 导出上报处理列表
     */
    //@RequiresPermissions("ziran:zrReport:export")
    @Log(title = "上报处理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZrReport zrReport)
    {
        List<ZrReport> list = zrReportService.selectZrReportList(zrReport);
        ExcelUtil<ZrReport> util = new ExcelUtil<ZrReport>(ZrReport.class);
        return util.exportExcel(list, "上报处理数据");
    }

    /**
     * 新增上报处理
     */
    @GetMapping("/add/{paperUserId}")
    public String add(@PathVariable("paperUserId") Long paperUserId,ModelMap mmap)
    {
        ZrPaperUser zrPaperUser=iZrPaperUserService.selectZrPaperUserById(paperUserId);
        if (zrPaperUser==null){
            throw new ServiceException("答题不存在");
        }
        mmap.put("paperId", zrPaperUser.getPaperId());
        mmap.put("paperUserId", paperUserId);
        mmap.put("studentName", zrPaperUser.getAnswerUserName());

        return prefix + "/add";
    }

    /**
     * 新增保存上报处理
     */
    //@RequiresPermissions("ziran:zrReport:add")
    @Log(title = "上报处理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ZrReport zrReport)
    {
        return toAjax(zrReportService.insertZrReport(zrReport));
    }

    /**
     * 修改上报处理
     */
    //@RequiresPermissions("ziran:zrReport:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ZrReport zrReport = zrReportService.selectZrReportById(id);
        mmap.put("zrReport", zrReport);
        return prefix + "/edit";
    }

    /**
     * 修改保存上报处理
     */
    //@RequiresPermissions("ziran:zrReport:edit")
    @Log(title = "上报处理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ZrReport zrReport)
    {
        return toAjax(zrReportService.updateZrReport(zrReport));
    }

    /**
     * 删除上报处理
     */
    //@RequiresPermissions("ziran:zrReport:remove")
    @Log(title = "上报处理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(zrReportService.deleteZrReportByIds(ids));
    }
}
